2022-11-28

How zig-spoon (and lots of coffee) helped me sort thousands of pictures

This is an archival copy of a recent post on zig.news. If you have any comments, please post them there instead.

I just had one of those wonderful moments where one of my free-time projects actually turns out to be useful in a real-world task.

So in a project for one of my university courses we have to train a neural network. Not exactly on-topic for my studies, but oh well. Unfortunately, the project involved getting the training data ourselves. Even more unfortunately, the way we took the pictures made it impossible to pre-sort them.

So here I was sitting with a directory of a few thousand pictures that needed labeling. We are sorting chess pieces by the way. I don't think there is any common tool out there to sort images like this and going through a normal file manager would have been insanely painful.

Luckily two things saved me:

  • My image viewer of choice, imv, can be remote-controlled.
  • I have written a TUI library for zig, allowing me to create user interfaces in basically no time.

So I created a little program to help with this task. It goes through all images in a directory, commanding the image viewer to display them and subsequently allowing me to quickly select the right label with keyboard shortcuts. For example if the image shows a white pawn, I press "wp" and the image gets automatically renamed. I implemented this such that I could also press "pw", because pressing keys in the right order gets kinda hard when you're tired. If the image is unusable (we picked up a decent amount of shadows, specs of dust and yes even rain drops with our detection method; don't ask), I press "r" for "reject".

Still super annoying; I went through four Stargate SG1 episodes and three cups of coffee for the first set alone. Yes, I basically CAPTCHA'd myself. But a considerable improvement over doing this manually. And all I had to do for this was read the manpage of my image viewer and slightly adapt one of zig-spoons example programs, which all-in-all took me about half an hour. That's basically nothing compared to the time sorting the pictures without this tools would have taken me.

Turns out that with the right libraries, zig is a great fit even for super-specific single-use programs like this one.

Articles from blogs I read (generated by openring)

Renting is for Suckers

Renting is for Suckers A genie offers you a choice: 50% chance to gain 10 million USD 100% chance to gain 1 million USD Which do you pick? Your answer, of course, depends on how much capital you have. If you are struggling to pay rent, then taking the less risk…

Andrew Kelley, July 24, 2025

Status update, July 2025

Hi! Sway’s patch to add HDR support has finally be merged! It can be enabled via output <name> hdr on, and requires the Vulkan renderer (which can be selected via WLR_RENDERER=vulkan). Still, lots remains to be done to improve tone mapping and compositi…

emersion, July 19, 2025

guile lab notebook: on the move!

Hey, a quick update, then a little story. The big news is that I got Guile wired to a moving garbage collector!Specifically, this is the mostly-moving collector with conservative stack scanning. Most collections will be marked in place. When the collector …

wingolog, July 8, 2025